package com.hawthorn.redis.controller;

import com.hawthorn.entity.po.SysRolePO;
import com.hawthorn.redis.service.role.RoleCacheService;
import com.hawthorn.redis.service.role.UserRoleCacheService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>todo 系统角色缓存</p>
 * @author: andy.ten@tom.com | xukaixing@hotmail.com
 * @created: 2021/12/19 2:25 PM
 * @version v1.0.1
 * @copyright: Copyright (c)  andyten
 */
@Api(tags = {"redis-sysrole"})
@RestController
@RequestMapping("/role")
@Slf4j
public class RoleCacheController
{
  @Autowired
  private RoleCacheService roleCacheService;

  @Autowired
  private UserRoleCacheService userRoleCacheService;

  // @Autowired
  // private RoleMenuCacheService roleMenuCacheService;

  /**
   * <p>todo 重新加载角色</p>
   * @author: andy.ten@tom.com
   * @date: 2021/12/20 8:37 PM
   * @version: 1.0.1
   */
  @ApiOperation(value = "加载->重新初始化角色", notes = "重新初始化角色")
  @ApiImplicitParams({

  })
  @GetMapping(value = "reloadRole")
  public void reloadRole()
  {
    roleCacheService.init();
  }

  /**
   * <p>todo 重新加载用户角色关系</p>
   * @author: andy.ten@tom.com
   * @date: 2021/12/20 8:38 PM
   * @version: 1.0.1
   */
  @ApiOperation(value = "加载->重新初始化用户角色关系", notes = "重新初始化用户角色关系")
  @ApiImplicitParams({
  })
  @GetMapping(value = "reloadUserRole")
  public void reloadUserRole()
  {
    userRoleCacheService.init();
  }

  /**
   * <p>todo 新增角色</p>
   * @author: andy.ten@tom.com ｜ xukaixing@hotmail.com
   * @date: 2022/8/1 18:14
   * @version: 1.0.1
   */
  @ApiOperation(value = "新增 -> 新增角色", notes = "新增角色")
  @ApiImplicitParams({
      @ApiImplicitParam(name = "sysRolePO", value = "sysRolePO", dataTypeClass = Object.class)
  })
  @PutMapping(value = "/saveRole")
  public void saveRole(@RequestBody SysRolePO sysRolePO)
  {
    roleCacheService.saveRole(sysRolePO);
  }

  /**
   * <p>todo 重新加载角色</p>
   * @author: andy.ten@tom.com ｜ xukaixing@hotmail.com
   * @date: 2022/8/1 14:55
   * @version: 1.0.1
   */
  @ApiOperation(value = "加载->重新加载角色", notes = "重新加载角色")
  @ApiImplicitParams({
      @ApiImplicitParam(name = "sysRolePO", value = "sysRolePO", dataTypeClass = Object.class)
  })
  @PostMapping(value = "/updateRole")
  public void updateRole(@RequestBody SysRolePO sysRolePO)
  {
    roleCacheService.updateRole(sysRolePO);
  }

}
